import { checkObjectValues, msg } from '/@/utils'
import { isNull } from '/@/utils';
import {InvAuditStockInDetail} from '../../../../api/inv/invShouGong/dto'

export const useValidateFun = (detailList: InvAuditStockInDetail[]) => {
  const formRef = ref()
  //  提交前的校验
  const validateFun = async () => {
    let isValid = true
    await formRef.value.validateFn((valid: boolean) => {
      isValid = valid
    })
    
    if(!isValid) {
      msg.error('存在未填写的必填项')
      return false
    }
    if(detailList.length == 0) {
      msg.error('请录入血液信息')
      return false
    }
    let noComplete = detailList.filter(d => { return checkObjectValues(d, [], ['id','billNo', 'oldBloodCode','specialProcessing', 'basBloodProductName'])==false })
    if(!isNull(noComplete) && noComplete.length > 0) {
      msg.error('存在未填写完整的血液信息')
      return false
    }
    return isValid
  }

  return {
    formRef,
    validateFun
  }
}